# -*- codeing = utf-8 -*-
# @Time: 2023/6/10 11:07
# @Author: caoyi
# @File: login_page.py
# @Software: PyCharm
# 登录页面
from selenium import webdriver
from selenium.webdriver.common.by import By

from tests.pages.base_page import BasePage
from tests.pages.index_page import IndexPage


class LoginPage(BasePage):
    '''
    登录页面，集成父类BasePage用于复用driver
    '''
    # 初始化
    def __init__(self,driver):
        super().__init__(driver)
        # # 只有driver是none才初始化
        # if driver is None:
        #     # pytest初始化方法，每次运行前执行
        #     # 打开Edge浏览器
        #     self.driver = webdriver.Edge()
        #     # 最大化窗口
        #     self.driver.maximize_window()
        #     # 设置隐式等待,等待页面元素加载完成之后，（无法等待js渲染的元素）(显式等待解决这个问题)
        #     self.driver.implicitly_wait(10)

    def open_login_page(self):
        # 打开登录页面
        login_url = "https://litemall.hogwarts.ceshiren.com/#/login?redirect=%2Fdashboard"
        self.driver.get(login_url)
    #     登录
    def click_login_btn(self):
        # 点击登录按钮
        # self.driver.find_element(By.XPATH,'//*[@id="app"]/div/form/div[3]').click()
        login_buttton = '//span[text()="登录"]'
        self.driver.find_element(By.XPATH, login_buttton).click()
        # 点击登录之后，返回首页
        return IndexPage(self.driver)